package com.taxshare.operation.controller;


import com.taxshare.operation.view.dto.DocumentDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.taxshare.mybatis.pager.PageRequest;
import com.taxshare.operation.service.DocumentService;
import com.taxshare.operation.view.vo.DocumentVO;
import com.taxshare.response.beans.Response;


/**
 * 文件管理
 *
 * @author liupp
 */
@RestController
@RequestMapping(value = "/document")
@Api(tags = "【文件管理】文件目录")
public class DocumentController {

	/**
     * 服务类
     */
    @Autowired
    private DocumentService documentService;
    
    /**
     * 列表信息查询
     */
    @RequestMapping(method = RequestMethod.POST, value = "/info/queryPageList")
    @ApiOperation(notes = "文件管理【分页】", value = "文件管理【分页】")
    public Response<IPage<DocumentVO>> queryPageList(@RequestBody PageRequest<DocumentVO> query) {
        return documentService.queryPageList(query);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/info/add")
    @ApiOperation(notes = "文件管理", value = "新增")
    public Response add(@RequestBody DocumentVO documentVO) {
        return documentService.add(documentVO);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/info/edit")
    @ApiOperation(notes = "文件管理", value = "编辑")
    public Response edit(@RequestBody DocumentVO documentVO) {
        return documentService.edit(documentVO);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/info/delete")
    @ApiOperation(notes = "文件管理", value = "删除")
    public Response delete(@RequestParam String uuid) {
        return documentService.delete(uuid);
    }
    
    @PostMapping(value = "/info/uploadOri")
    @ApiOperation(notes = "文件管理", value = "文件上传")
    public Response uploadOri(@RequestParam("files") MultipartFile files,@RequestParam String uuid){
    	return documentService.uploadFile(files,uuid);
    }
    
    @GetMapping(value = "/info/down")
    @ApiOperation(notes = "文件管理", value = "下载文件")
    public void down(HttpServletResponse response,@RequestParam String uuid){
    	documentService.down(response, uuid);
    }

    @GetMapping(value = "/info/downTemplate")
    @ApiOperation(notes = "模板文件下载", value = "模板文件下载")
    public void downTemplate(HttpServletResponse response,@RequestParam String documentCode){
        documentService.downTemplate(response, documentCode);
    }

}